package com.comdo.newup_loan.module.repayment_action;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.comdo.newup_loan.R;
import com.comdo.newup_loan.base.BaseActivity;
import com.comdo.newup_loan.comom.Config;
import com.comdo.newup_loan.model.ToXuDaiApply;
import com.comdo.newup_loan.module.recharge.MineTopUpActivity;
import com.comdo.newup_loan.util.StringUtils;
import com.comdo.newup_loan.util.TitleMenuUtil;

import butterknife.BindView;

/**
 * Created by liyuan on 2017/11/6.
 */

public class XudaiActivity extends BaseActivity<XudaiPersenter> implements View.OnClickListener, XudaiContact.View {
    @BindView(R.id.ll_recharge)
    LinearLayout mRechargeLin;
    @BindView(R.id.btn_submit)
    Button mSubmitBtn;
    @BindView(R.id.tv_left_amount)
    TextView mLeftAmountText;
    @BindView(R.id.ed_percent)
    EditText mPercentEdit;
    @BindView(R.id.tv_yhbj)
    TextView yhbjText;
    @BindView(R.id.tv_yhlx)
    TextView yhlxText;
    @BindView(R.id.tv_yhglf)
    TextView yhglfText;
    @BindView(R.id.tv_fxj)
    TextView fxjText;
    @BindView(R.id.tv_gps)
    TextView gpsText;
    @BindView(R.id.tv_tcf)
    TextView tcfText;
    @BindView(R.id.tv_yhze)
    TextView yhzeText;
    private int id;
    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_repayment_xudai;
    }

    @Override
    protected void init() {
        super.init();
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        new TitleMenuUtil(XudaiActivity.this, "续贷", true);
        mSubmitBtn.setOnClickListener(this);

        mRechargeLin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(XudaiActivity.this, MineTopUpActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public XudaiPersenter getmPresenter() {
        return new XudaiPersenter();
    }

    @Override
    public void presenterSetView() {
        if (mPresenter != null)
            mPresenter.setView(this);
    }

    @Override
    public void getFail(String failMessage) {
        showToast(failMessage);
    }

    @Override
    public void getData(ToXuDaiApply datas) {
        id=datas.getId();
        mLeftAmountText.setText(StringUtils.getMoneyString(datas.getBalanceMoney()));
        mPercentEdit.setText(StringUtils.getMoneyString(datas.getRate()));
        //应还本金
        yhbjText.setText(StringUtils.getMoneyString(datas.getPrinciple()));
        //应还利息
        yhlxText.setText(StringUtils.getMoneyString(datas.getSqdjCost()));
        //应还管理费
        yhglfText.setText(StringUtils.getMoneyString(datas.getManageCost()));
        //应还风险金
        fxjText.setText(StringUtils.getMoneyString(datas.getRiskCost()));
        //应还gps使用费
        gpsText.setText(StringUtils.getMoneyString(datas.getGpsUseCost()));
        //应还停车费
        tcfText.setText(StringUtils.getMoneyString(datas.getCarStopCost()));
        //应还总额
        yhzeText.setText(StringUtils.getMoneyString(datas.getTotalPay()));
    }

    @Override
    public void goOnLoan(String result) {
        showToast(result);
        finish();
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_submit:
                mPresenter.goOnLoan(id, Config.loginInfo.getUserId());
                break;
        }

    }
    @Override
    public void onResume() {
        super.onResume();
        mPresenter.getData(getIntent().getIntExtra("repayPlanId",0),Config.loginInfo.getUserId());
    }
}
